/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vn.support.ui.frame;

import java.awt.Component;
import java.awt.Dimension;
import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
import vn.support.core.dto.Staff;
import vn.support.system.SystemProperties;

/**
 *
 * @author nttuyen
 */
public class StaffTreeCellRender extends DefaultTreeCellRenderer {
    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        DefaultTreeCellRenderer render = (DefaultTreeCellRenderer) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
        render.setMinimumSize(new Dimension(100, 20));
        if(value instanceof StaffMutableTreeNode) {
            StaffMutableTreeNode staffTreeNode = (StaffMutableTreeNode) value;
            Staff staff = (Staff)staffTreeNode.getUserObject();
            int status = staff.getStatus();
            if(status == 0) status = ((Integer)SystemProperties.get(SystemProperties.CURRENT_STATUS)).intValue();
            Icon icon = SystemProperties.getIcon("support.chat.staff.status." + status);
            render.setIcon(icon);
            if(status != 2 && status != 7) {
                render.setText("<html><b>" + render.getText() + "</b></html>");
            }
        }
        return render;
    }
}
